package com.dingding.manager.modules.system.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.dingding.manager.common.beans.sys.SysMenu;
import com.dingding.manager.modules.system.service.MenuService;

/**
* @ClassName: MenuController 
* @Description:菜单管理controller 
* @author SUNZHICHENG 
* @date 2016年12月4日 上午1:15:18 
* @version V2.6.2
 */
@Controller
@RequestMapping("sys/v1/menu")
public class MenuController {
	
	@Resource(name="menuService")
	MenuService menuService;
	
	
	/**
	 * @Description:根据当前登录用户获取用户所能操作的菜单 
	 * @date 2016年12月4日 上午1:22:22
	 * @author SUNZHICHENG 
	 * @since V2.6.2
	 */
	@RequestMapping("/menulist")
	public void getMenuListByUserName(HttpServletRequest request, HttpServletResponse response){
		//获取当前登录用户
		Subject subject = SecurityUtils.getSubject();
		String userName  = (String) subject.getPrincipal();
		//查询菜单列表
		List<SysMenu> menuList = menuService.getMenuByUserName(userName);
		
		if (menuList.size()==0) {
			return ;
		}
		
		String jsonString = JSON.toJSONString(menuList);
		try {
			response.getWriter().println(jsonString);
		} catch (IOException e) {
			
			e.printStackTrace();
		}
	}
}
